var Narato=(function($){
	var p={},pub={};
    /*private area*/
	p._modules={};
	/*
	initVar方法
	作用：用于引用重复使用的dom元素或引用服务器端生成到页面的js变量
	*/
    p.initVar = function(opts) { };
	/*
	onLoaded方法
	作用:统一管理页面加载完毕后的回调方法
	说明:onLoaded方法接管所有页面上注册到$(document).ready(callback)中的callback方法;
		如果你要新增一个$(callback)或$(document).ready,请将你的callback方法放在onLoaded方法体内
	*/
    p.onLoaded = function() { 
		for(var m in p._modules){
			if((m=p._modules[m])&&m.onLoad){
				m.onLoad(m);
			};
		};
	};
	/*
	initEvents方法
	作用:用于为页面dom元素注册各种事件!
	说明:Html页面仅用于表现，任何时候应在标签里面直接注册事件。即避免如<a onclick="xx"/>
	*/
    p.initEvents = function(opts) {
        $(document).ready(p.onLoaded);
    };
	/* updateCookie */
	p.updateCookie=function(target, data) {
		var cookie = target.replace(/[#. ]/g, '');
		$.cookie(cookie, data, {
			path: '/'
		});
	};
	/* module-readmorelink */
	p._modules.readmorelink={
		init:function(){
			$('a.more-link').click(function () {
				var target_url = $(this).attr('href'),
					pos = target_url.lastIndexOf('-'),
					postid = target_url.substr(++pos),
					link = $(this),
					content = $(this).parent(),
					more_content = $("<div></div>");

				link.html('').addClass('loading');

				// perform the ajax request
				$.ajax({
					type: "POST",
					url: target_url,
					dataType: "html",
					cache: false,
					data: {
						'redirect-more-link': 1,
						'postid': postid
					},
					error: function (request, textStatus, errorThrown) {
						window.location = link.attr('href'); // go to link
					},
					success: function (data, textStatus) {
						more_content.html(data).hide();
						content.append(more_content);
						link.remove();
						more_content.slideFade('show',333, 'easeOutCubic', function () {});
					}

				});
				return false;
			});
		}
	};

	/* public methods
	++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	/*
	Init方法
	作用:页面js逻辑的唯一入口
	说明：理想状态下每个页面对应一个交互用的js文件，在页面末尾通过下面代码初始化js交互逻辑
	<script type="text/javascript">
	//<![CDATA[
	this$.Init({x:'kk',y:'zz'});
	//]]>
	</script> 
	*/
    pub.Init = function(opts) {
		for(var m in p._modules){
			if((m=p._modules[m])&&m.init){
				m.init(opts);
			};
		};
        p.initVar(opts);
        p.initEvents(opts);
    };
	/**
	 * 往当前页面JS逻辑注册一个功能模块.请在Init方法前调用
	 * @param {Object} key
	 * @param {Object} module 如'{init:function(opts){},onLoad:function(opts){}}'
	 */
	pub.AddModule=function(key,module){
		if (p._modules[key]) {
			alert("Module with key '"+key+"' has beed registered!");
			return;
		};
		p._modules[key]=module;
		//register namespace
		pub[key]=module;
		return pub;
	};
	/**
	 * 获取指定注册的模块
	 * @param {Object} key
	 */
	pub.GetModule=function(key){
		return p._modules[key];
	};
	/**
	 * shortcut method for AddModule & GetModule
	 */
	pub.M=function(key,module){
		if(arguments.length==1){
			return pub.GetModule(key);
		};
		if(arguments.length==2){
			return pub.AddModule(key, module);
		};
		return null;
	};
	/**
	 * fontControl
	 */
	pub.fontControl=function(container, target, minSize, maxSize) {
		var cookie = 'page-font-size',
			value = $.cookie(cookie);
		if (value != null) {
			$(target).css('fontSize', parseInt(value));
		}; 
		//on clicking small font button, font size is decreased by 1px
		$(container + " .fontSize").click(function () {
			curSize = parseInt($(target).css("fontSize"));
			newSize = curSize + 1;
			if (newSize > maxSize) newSize = minSize;
			if (newSize >= minSize) //jQuery(target).css('fontSize', newSize);
				$(target).animate({fontSize: newSize},333, 'swing');

			p.updateCookie(cookie, newSize); //sets the cookie
		});
	};
	/**
	 * pageWithControl
	 */
	pub.pageWidthControl=function(container, target, fullWidth, fixedWidth, fluidWidth) {
		$(container).append('<a href="javascript:void(0);" class="pageWidth bubble" title="switch from fixed to fluid page width"></a>');
		var cookie = 'page-max-width',
			value = $.cookie(cookie);
		if (value != null) {
			$(target).css('maxWidth', value);
		};
		$(container + " .pageWidth").click(function () {
			curMaxWidth = $(target).css('maxWidth');
			newMaxWidth = curMaxWidth;
			switch (curMaxWidth) {
				case fullWidth:
					newMaxWidth = fixedWidth;
				break;
				case fixedWidth:
					newMaxWidth = fluidWidth;
				break;
				case fluidWidth:
					newMaxWidth = fullWidth;
				break;
				default:
					newMaxWidth = fluidWidth;
			};
			$(target).animate({maxWidth: newMaxWidth},333, 'easeOutQuart');
			p.updateCookie(cookie, newMaxWidth); //sets the cookie
		});
	};

	/**
	 * simple tooltips
	 */
	pub.webshot=function(target_items, name) {
		$(target_items).each(function (i) {
			$("body").append("<div class='" + name + "' id='" + name + i + "'><img src='http://images.websnapr.com/?size=s&amp;url=" + $(this).attr('href') + "' width='202' height='152' /></div>");
			var my_tooltip = $("#" + name + i);
			$(this).mouseover(function () {
				my_tooltip.css({
					opacity: 1,
					display: "none"
				}).fadeIn(333);
			}).mousemove(function (kmouse) {
				my_tooltip.css({
					left: kmouse.pageX + 15,
					top: kmouse.pageY + 15
				});
			}).mouseout(function () {
				my_tooltip.fadeOut(333);
			});
		});
	};

	pub.liteboxCallback=function() {
		jQuery('.flickrGallery li a').fancyboxlite({
			'zoomSpeedIn': 333,
			'zoomSpeedOut': 333,
			'zoomSpeedChange': 133,
			'easingIn': 'easeOutQuart',
			'easingOut': 'easeInQuart',
			'overlayShow': true,
			'overlayOpacity': 0.75
		});
	};

	return pub;
})(jQuery);